package com.tlx.core.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.UUID;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;

public class TlxUtils {

    // private final static Logger logger =
    // Logger.getLogger(PiaohanUtils.class);

    public static final String PREFIX = "XUEPIAOHANTEMPPREFIX";

    public static void main(String[] args) throws Exception {
        String cmd = "wkhtmltopdf -B 0 -L 0 -R 0 -T 0  --page-height 2000 --page-width 210  \"http://blog.csdn.net/zhangkezhi_471885889/article/details/52184744\" \"D:/0/2.pdf\"";
        System.out.println(execNative(cmd));
    }

    public static String execNative(String command) {
        InputStream is = null;
        try {
            Process process = Runtime.getRuntime().exec(command);
            is = process.getInputStream();
            return IOUtils.toString(is);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }

    public static String getUuid() {
        try {
            UUID uuid = UUID.randomUUID();
            return md5(uuid.toString()).toUpperCase();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String md5(String sString) {
        try {
            return DigestUtils.md5Hex(sString);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String md5File(String filePath) {
        try {
            InputStream is = new FileInputStream(filePath);
            try {
                return DigestUtils.md5Hex(is);
            } finally {
                IOUtils.closeQuietly(is);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
